package com.dony.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dony.common.annotation.Log;
import com.dony.common.core.controller.BaseController;
import com.dony.common.core.domain.AjaxResult;
import com.dony.common.core.page.TableDataInfo;
import com.dony.common.enums.BusinessType;
import com.dony.common.utils.SecurityUtils;
import com.dony.shop.domain.ShopeeMerchant;
import com.dony.shop.service.IShopeeMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Dominic
 * @date 2022-08-23
 */
@RestController
@RequestMapping("/shopee/merchant")
public class ShopeeMerchantController extends BaseController
{

    @Autowired
    IShopeeMerchantService merchantService;

    /**
     * 查询授权商户列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ShopeeMerchant merchant)
    {
        startPage();
        List<ShopeeMerchant> list = merchantService.listByParam(merchant);
        return getDataTable(list);
    }

    /**
     * 获取全球商户下拉列表
     *
     * @return
     */
    @RequestMapping("/listAll")
    public AjaxResult getMerchantList() {
        return AjaxResult.success(merchantService.listByTenant());
    }


    /**
     * 获取授权详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(merchantService.getById(id));
    }


    /**
     * 修改商户信息
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ShopeeMerchant merchant)
    {
        return toAjax(merchantService.updateRemark(merchant));
    }

    /**
     * 删除授权店铺
     */
    @Log(title = "授权店铺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(merchantService.removeBatchByIds(Arrays.stream(ids).collect(Collectors.toList())));
    }
}
